package com.yy.jhl.ui.manager.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yy.common.base.BaseAdapter;
import com.yy.common.commonwidget.OnNoDoubleClickListener;
import com.yy.jhl.R;
import com.yy.jhl.bean.JGOrderInfo;
import com.yy.jhl.ui.manager.activity.JGOrderDetailActivity;
import com.yy.jhl.ui.manager.activity.OrderDetailActivity;
import com.yy.jhl.ui.manager.activity.OrderFlowActivity;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Ellis.Li on 2017/6/15.
 */

public class JGOrderDetailAdapter extends BaseAdapter {
    private List<JGOrderInfo> modelList;
    public JGOrderDetailAdapter(Context context) {
        super(context);
        modelList = new ArrayList<>();
    }
    @Override
    public void removeItem(int position) {
        super.removeItem(position);
        modelList.remove(position);
        notifyDataSetChanged();
    }
    @Override
    public void clearData() {
        super.clearData();
        modelList.clear();
        notifyDataSetChanged();
    }
    public void addData(List<JGOrderInfo> monomerModels) {
        modelList.addAll(monomerModels);
        notifyDataSetChanged();
    }

    public void addAllData(List<JGOrderInfo> monomerModels) {
        clearData();
        modelList.addAll(monomerModels);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return modelList.size();
    }

    @Override
    public Object getItem(int i) {
        return modelList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        Holder storeHolder;
        if(view == null){
            storeHolder = new Holder();
            view = layoutInflater.inflate(R.layout.item_jg_order_detail,null);
            storeHolder.initView(view);
            view.setTag(storeHolder);
        }else{
            storeHolder = (Holder)view.getTag();
        }
        final JGOrderInfo itemModel = modelList.get(i);
        storeHolder.order_name_text.setText(itemModel.getTitle());
        storeHolder.order_time_text.setText(itemModel.getUpdate_time());
        storeHolder.order_gys_text.setText(itemModel.getCompany_supply_name());
        storeHolder.order_code_text.setText(itemModel.getOrder_sn());
        storeHolder.order_status_text.setText(itemModel.getStatus());
        storeHolder.order_product_text.setText(itemModel.getOrder_info());
        storeHolder.order_progress_text.setText(itemModel.getOrder_ratio()+"%");
        storeHolder.look_order_text.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                //查看监管单
                JGOrderDetailActivity.startAction(mContext,itemModel.getOrder_id(),false);
            }
        });
        storeHolder.manager_text.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                //进入监管流程
                OrderFlowActivity.startAction(mContext,itemModel.getOrder_id());
            }
        });
        return view;
    }
    /**
     *
     */
    class Holder{
        private ImageView status_red_img;
        private TextView order_name_text;
        private TextView order_time_text;
        private TextView order_gys_text;
        private TextView order_code_text;
        private TextView order_status_text;
        private TextView order_product_text;
        private TextView order_progress_text;
        private LinearLayout progress_parent;
        private TextView look_order_text;
        private TextView manager_text;
        void initView(View view) {
            status_red_img = (ImageView) view.findViewById(R.id.status_red_img);
            order_name_text = (TextView) view.findViewById(R.id.order_name_text);
            order_time_text = (TextView) view.findViewById(R.id.order_time_text);
            order_progress_text = (TextView) view.findViewById(R.id.order_progress_text);
            order_gys_text = (TextView) view.findViewById(R.id.order_gys_text);
            order_code_text = (TextView) view.findViewById(R.id.order_code_text);
            order_status_text = (TextView) view.findViewById(R.id.order_status_text);
            order_product_text = (TextView) view.findViewById(R.id.order_product_text);
            look_order_text = (TextView) view.findViewById(R.id.look_order_text);
            manager_text = (TextView) view.findViewById(R.id.manager_text);
            progress_parent = (LinearLayout) view.findViewById(R.id.progress_parent);
        }

    }
}
